#define _CRT_SECURE_NO_WARNINGS 1
#include"Queue.h"


Queue* QueueInit()
{
	Queue* queue = (Queue*)malloc(sizeof(Queue));
	if (queue == NULL)
	{
		perror("malloc");
		return;
	}
	queue->head = queue->tail = NULL;
	return queue;
}

bool QueueIsEmpty(Queue* queue)
{
	assert(queue);
	return queue->head == NULL;
}

void InQueue(Queue* queue,DataType x)
{
	Node* newnode = (Node*)malloc(sizeof(Node));
	newnode->next = NULL;
	newnode->val = x;
	if (queue->head == NULL)
	{
		queue->head = queue->tail = newnode;
	}
	else
	{
		queue->tail->next = newnode;
		queue->tail = newnode;
	}
}

void DeQueue(Queue* queue)
{
	assert(queue);
	assert(!QueueIsEmpty(queue));
	if (queue->head->next == NULL)
	{
		free(queue->head);
		queue->head =queue->tail= NULL;
		return;
	}
	else
	{
		Node* tmp = queue->head;
		queue->head = queue->head->next;
		free(tmp);
	}
}

void QueuePrint(Queue* queue)
{
	assert(queue);
	if (!QueueIsEmpty(queue))
	{
		Node* current = queue->head;
		while (current)
		{
			printf("%d ", current->val);
			current = current->next;
		}
	}
}

